package cn.wizzer.framework.filter;

import cn.wizzer.framework.util.Result;
import cn.wizzer.framework.util.debug.Debug;
import cn.wizzer.framework.util.debug.DebugUtil;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.View;

@IocBean(singleton=false)
public class DebugFilter implements ActionFilter {
    private static final Log log = Logs.get();

    @Override
    public View match(ActionContext actionContext) {
        Debug debug = actionContext.getMethod().getDeclaringClass().getAnnotation(Debug.class);
        if (debug == null) {
            debug = actionContext.getMethod().getAnnotation(Debug.class);
        }
        if (debug != null) {
            if (!actionContext.getIoc().get(DebugUtil.class).isDebugging()) {
                Result.error(actionContext.getResponse(),-4);
            }
        }
        //正常处理下一调用链环节
        return null;
    }
}
